const koa = require('koa')
const app = new koa()

const main = ctx => {
    if(ctx.request.accepts('xml')){
        ctx.response.type = 'xml'
        ctx.response.body = '<data>hello</data>'
    }else if(ctx.request.accepts('json')){
        ctx.response.type = 'json'
        ctx.response.body = {name:'cll'}
    }else if(ctx.request.accepts('html')){
        ctx.response.type = 'html'
        ctx.response.body = '<html><body><h1>hello</h1></body></html>'
    }else{
        ctx.response.type = 'text'
        ctx.response.body = '返回的是文本'
    }
}
app.use(main)


app.listen(3000)